<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="菜品名称" prop="foodname">
        <el-input
          v-model="queryParams.foodname"
          placeholder="请输入菜品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="菜品规格" prop="foodspec">
        <el-input
          v-model="queryParams.foodspec"
          placeholder="请输入菜品规格"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生效日期" prop="effectiveDate">
        <el-date-picker clearable size="small" style="width: 200px" v-model="queryParams.effectiveDate" type="date" value-format="yyyy-MM-dd" placeholder="选择开始时间"/> -
        <el-date-picker clearable size="small" style="width: 200px" v-model="queryParams.maxEffectiveDate" type="date" value-format="yyyy-MM-dd" placeholder="选择结束时间"/>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['mt:foodcostcard:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="foodcostcardList" >
      <el-table-column label="菜品Sku" align="center" prop="foodskuid" />
      <el-table-column label="菜品名称" align="center" prop="foodname" />
      <el-table-column label="菜品规格" align="center" prop="foodspec" />
      <el-table-column label="生效日期" align="center" prop="effectiveDate" width="180">
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.effectiveDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-info" size="mini" @click="getFoodcostcardInfo(scope.row.id)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog title="成本卡详情" :visible.sync="open1" width="90%" append-to-body>
      <el-form :model="form" :inline="true" label-width="100px">
        <el-form-item label="菜品名称:" prop="foodname">
          <span>{{form.foodname}}</span>
        </el-form-item>
        <el-form-item label="菜品Sku:" prop="foodskuid">
          <span>{{form.foodskuid}}</span>
        </el-form-item>
      </el-form>
      <el-table :data="foodCostCardItemList" v-loading="loading1">
        <el-table-column label="美团编号" align="center" prop="mtGoodsCode"/>
        <el-table-column label="美团物品" align="center" prop="mtGoodsName"/>
<!--        <el-table-column label="菜品Sku" align="center" prop="foodskuid"/>-->
<!--        <el-table-column label="菜品" align="center" prop="foodname"/>-->
        <el-table-column label="数量" align="center" prop="amount">
          <template slot-scope="scope">
            <span>{{scope.row.amount}}{{scope.row.baseunitName}}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime"/>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { listFoodcostcard, exportFoodcostcard } from "@/api/mt/foodcostcard";
import {listFoodcostcardItem} from '@/api/mt/foodcostcardItem'

export default {
  name: "mtFoodcostcard",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      loading1:false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 美团成本卡主表格数据
      foodcostcardList: [],
      //成本卡详情数据
      foodCostCardItemList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //成本卡详情控制
      open1:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        foodskuid: null,
        foodname: null,
        foodspec: null,
        effectiveDate: null,
        status: null,
        maxEffectiveDate:null,
      },
      // 表单参数
      form: {
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getFoodcostcardInfo(id){
      this.loading1=true;
      this.open1=true;
      listFoodcostcardItem({mtFoodcostcardid:id}).then(response=>{
        if (response.code==200){
          this.foodCostCardItemList=response.rows;
          if (this.foodCostCardItemList.length>0){
            this.form=this.foodCostCardItemList[0];
          }
          this.loading1=false;
        }
      })
    },
    /** 查询美团成本卡主列表 */
    getList() {
      this.loading = true;
      listFoodcostcard(this.queryParams).then(response => {
        this.foodcostcardList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        foodskuid: null,
        foodname: null,
        foodspec: null,
        effectiveDate: null,
        status: 0,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有美团成本卡数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportFoodcostcard(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
